package ext.trace.kernel;

import math.math;

public class KernelWindowedSinc implements Kernel
{
    
    private static final double COEFF = 0.62329436051;
    
    private static final double EPSILON = 1.0e-7;
    
    
    public KernelWindowedSinc()
    {
        
    }
    
    
    public double eval(double aRadius, double aExtent)
    {
        if (aRadius < EPSILON) // Sinc(x) is undef. at x=0, so use the limit as x->0.
        {
            double peak = COEFF * 1.25 * math.PI / aExtent;
            return peak;
        }
        double radOverExt = aRadius / aExtent;
        double sin = math.sin(1.25 * math.PI * radOverExt);
        double cos = math.cos(0.5 * math.PI * radOverExt);
        double eval = COEFF * sin * cos / aRadius;
        return eval;
    }
    
}
